﻿using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {
	
	[SerializeField]
	public UIToolkit tkMainMenu;
	
	private  UISprite uiBackground;
	private UISprite uiName;
	private UIVerticalLayout uiVerLayout;
	private MainMenuViewModel mmController;
	
	//Menu Buttons
	private UIButton btnStart;
	private UIButton btnOption;
	private UIButton btnExit;
	private UIButton btnTitle;
	
	
	
	
	void Start () {
		CreateMenu();
	}
	
	public void CreateMenu()
	{
		CreateControls();
		ResizeControls();
		PositionControls();
		PutActions();
	}
	
	public void CreateControls()
	{
		mmController = new MainMenuViewModel();
		uiBackground = UI.firstToolkit.addSprite("backgroundN.png",0,0,8);
		//uiName = UI.firstToolkit.addSprite("TitleGame.png",0,0,7);
		uiVerLayout = new UIVerticalLayout(40);
		uiVerLayout.beginUpdates();
		uiVerLayout.addChild(GetBtnStart());
		uiVerLayout.addChild(GetBtnOption());
		uiVerLayout.addChild(GetBtnExit());
		uiVerLayout.endUpdates();
	}
	
	public void PositionControls()
	{
		//uiName.positionFromBoto(0.1f,0.1f);
		uiBackground.positionCenter();
		uiVerLayout.positionFromTopRight(0.2f,0.4f);
	}
	
	public void ResizeControls()
	{
		uiBackground.setSize(Screen.width,Screen.height);
	}
	
	public void PutActions()
	{
		GetBtnStart().onTouchUp += mmController.StartGame;
		GetBtnOption().onTouchUp+= mmController.showOption;
		GetBtnExit().onTouchUp+= mmController.ExitGame;
	}
	
	private UIButton GetBtnStart()
	{
		if(btnStart == null){
			btnStart = UIButton.create(tkMainMenu,"btnStartUp.png","btnStartDown.png",0,0,4);
		}
		return btnStart;
	}
	
	private UIButton GetBtnOption()
	{
		if(btnOption == null){
			btnOption = UIButton.create(tkMainMenu,"btnOptionUp.png","btnOptionDown.png",0,0,4);
		}
		return btnOption;
	}
	
	private UIButton GetBtnExit(){
		if(btnExit == null){
			btnExit = UIButton.create(tkMainMenu, "btnExitUp.png","btnExitDown.png",0,0,4);
		}
		return btnExit;
	}
}
